/*
 *   日志打印
 */
#pragma once

#include <cstdint>
#include <cstdio>
#include <cstring>

#include "utilitys.h"

namespace wheels {

enum color {
    traceattr_fontcolor_black = 0,
    traceattr_fontcolor_red,
    traceattr_fontcolor_green,
    traceattr_fontcolor_yellow,
    traceattr_fontcolor_blue,
    traceattr_fontcolor_purple,
    traceattr_fontcolor_darkgreen,
    traceattr_fontcolor_white,
    traceattr_fontcolor_num,
};

int32_t trace_logger(FILE *stm, color c, const char *branch, const char *ver, const char *file, const char *func,
                     uint32_t line, const char *fmt, ...) __attribute__((format(printf, 8, 9)));

}  // namespace wheels

#ifndef LOG_LIB_VERSION
#define LOG_LIB_VERSION "Unknown"
#endif

#ifndef LOG_LIB_NAME
#define LOG_LIB_NAME "Unknown"
#endif

/// 日志输出
#define trace_info(fmt, arg...)                                                                                           \
    wheels::trace_logger(stdout, wheels::traceattr_fontcolor_white, LOG_LIB_NAME, LOG_LIB_VERSION,                     \
                         wheels::xc_basename(__FILE__), __func__, __LINE__, fmt, ##arg)

#define trace_warn(fmt, arg...)                                                                                           \
    wheels::trace_logger(stdout, wheels::traceattr_fontcolor_yellow, LOG_LIB_NAME, LOG_LIB_VERSION,                    \
                         wheels::xc_basename(__FILE__), __func__, __LINE__, fmt, ##arg)

#define trace_err(fmt, arg...)                                                                                            \
    wheels::trace_logger(stderr, wheels::traceattr_fontcolor_red, LOG_LIB_NAME, LOG_LIB_VERSION,                       \
                         wheels::xc_basename(__FILE__), __func__, __LINE__, fmt, ##arg)
